package com.senjoeson.abilityservice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;

/**
 * @USER senjoeson
 * @DATE 2021/1/31 12:16 上午
 * @Desc
 **/
public class TestView extends View {


    private Point mCenter;

    public TestView(Context context) {
        this(context, null);

        init(context);
    }

    public TestView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TestView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void init(Context context) {
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        final DisplayMetrics metrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getRealMetrics(metrics);
        mCenter = new Point((int) metrics.widthPixels / 2, (int) metrics.heightPixels / 2);
    }

    Path path = new Path();
    Paint paint = new Paint();

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(2);
        paint.setStyle(Paint.Style.STROKE);
//        path.moveTo(mCenter.x * 2, mCenter.y);//先移动到右侧的边线中间.
//        //然后向左移动
//        path.lineTo(0, mCenter.y);
        path.moveTo(1080, 1920>>1);
        // 连接路径到点[100,100]
        path.lineTo(0, 1920>>1);
        canvas.drawPath(path, paint);
    }
}
